package com.example.composableexample.drawer.common

import androidx.compose.foundation.layout.Box
import androidx.compose.foundation.layout.WindowInsets
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.offset
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.ArrowBack
import androidx.compose.material.icons.filled.Menu
import androidx.compose.material3.ExperimentalMaterial3Api
import androidx.compose.material3.Icon
import androidx.compose.material3.IconButton
import androidx.compose.material3.MaterialTheme
import androidx.compose.material3.Text
import androidx.compose.material3.TopAppBar
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.TopAppBarScrollBehavior
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.text.font.FontWeight
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import androidx.navigation.NavHostController

/**
 * author: LiLiang
 * createTime: 2022/9/30-23:38
 * remark:
 **/

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CustomToolBar(
    modifier: Modifier = Modifier,
    title: String,
    onButtonClicked: () -> Unit,
    scrollBehavior: TopAppBarScrollBehavior = TopAppBarDefaults.pinnedScrollBehavior()
) {
        TopAppBar(
            windowInsets = WindowInsets(top = 5),
            modifier = modifier,
            scrollBehavior = scrollBehavior,
            title = {
                Text(text = title, fontSize = 16.sp, fontWeight = FontWeight.Bold, modifier = Modifier.offset(y = 8.dp))
            },
            navigationIcon = {
                IconButton(onClick = { onButtonClicked() },modifier = Modifier.offset(y = 8.dp)) {
                    Icon(imageVector = Icons.Default.Menu, contentDescription = title)
                }
            }
        )
}

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun CustomToolbarWithBackArrow(title: String, navController: NavHostController) {
    TopAppBar(
        title = { Text(text = title, style = MaterialTheme.typography.titleMedium) },
        navigationIcon = {
            IconButton(onClick = { navController.popBackStack() }) {
                Icon(
                    Icons.Filled.ArrowBack,
                    contentDescription = ""
                )
            }
        }
    )
}